package com.apache.database.model;

import java.io.Serializable;
import java.util.List;


/**
 * description: 分页实体Bean，包含分页逻辑和前台显示代码
 * 
 * @author Hou DaYu 
 */
@SuppressWarnings("serial")
public class Page implements Serializable {

	private int count = 0; // 记录总数
	private int pageSize = -1; // 每页记录数
	private int pageCount = 0; // 总页数
	private int pageNeeded = 1; // 当前页码
	private int startRow = 1; // 记录开始数
	private int endRow = 15; // 记录结束数
	private String sortFieldName; // 排序字段
	private String sortByAD; // 排序方式
	private String isNeedCount = "true"; // 是否需要重新从数据库中获取记录总数 
	private static int maxPageSize = 100; // 默认每页的最大数 
	public static final String PAGER_IMAGE_LOCATION_PATH = "pagerImageLocationPath"; // 图片存放路径常量字符串
	@SuppressWarnings("rawtypes")
	private List pageObjects;

	/**
	 * 排序sql字符串,例如现在要用字段fiedl_1进行倒序,field_2 进行顺序排序.则该字符串的内容为: "field_1
	 * asc,field_2 asc" 如果只有单个排序字段则直接写成:"field_1 asc"
	 */
	private String orderByStr;

	public Page() {
	}

	/**
	 * 
	 */
	public Page(String sortFieldName, String sortByAD) {
		this.sortFieldName = sortFieldName;
		this.sortByAD = sortByAD;
	}

	/**
	 * 设置总记录数,同时根据总记录数计算总页数,开始记录数,截止记录数
	 * 
	 */
	public void setCount(int totalRows) {
		if (pageSize != 0) {
			pageCount = totalRows / pageSize;
			if (totalRows % pageSize != 0) {
				pageCount++;
			}
		}
		this.count = totalRows;

		if (pageCount < pageNeeded) {
			pageNeeded = 1;
		}

		startRow = (getPageNeeded() - 1) * getPageSize() + 1;
		endRow = getPageSize() * getPageNeeded();
		if (endRow > totalRows)
			endRow = totalRows;

	}

	/*	*/
	/**
	 * 
	 * @return 返回对应value
	 */
	/*
		public String getText(String key) {
			return struts2i18nUtil.getText(key);
		}
	*/
	public int getCount() {
		return count;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNeeded() {
		return pageNeeded;
	}

	public void setPageNeeded(int pages) {
		this.pageNeeded = pages;
	}

	public int getMaxPageSize() {
		return maxPageSize;
	}

	public void setMaxPageSize(int maxPageSize) {
		Page.maxPageSize = maxPageSize;
	}

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getEndRow() {
		return endRow;
	}

	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}

	public String getSortFieldName() {
		return sortFieldName;
	}

	public void setSortFieldName(String sortFieldName) {
		this.sortFieldName = sortFieldName;
	}

	public String getSortByAD() {
		return sortByAD;
	}

	public void setSortByAD(String sortByAD) {
		this.sortByAD = sortByAD;
	}

	public String getIsNeedCount() {
		return isNeedCount;
	}

	public void setIsNeedCount(String isNeedCount) {
		this.isNeedCount = isNeedCount;
	}

	@SuppressWarnings("rawtypes")
	public List getPageObjects() {
		return pageObjects;
	}

	@SuppressWarnings("rawtypes")
	public void setPageObjects(List pageObjects) {
		this.pageObjects = pageObjects;
	}

	public String getOrderByStr() {
		return orderByStr;
	}

	/**
	 * 设置排序sql字符串
	 * 
	 * 字符串传递规则:例如现在要用字段fiedl_1进行倒序,field_2 进行顺序排序. 则该字符串的内容为: "field_1
	 * asc,field_2 asc" 如果只有单个排序字段则直接写成:"field_1 asc"
	 * 
	 * @param orderByStr
	 */
	public void setOrderByStr(String orderByStr) {
		this.orderByStr = orderByStr;
	}

}
